package graphics.raytracing.shaders;

import static util.MatrixOperationsF.ar;
import static util.MatrixOperationsF.multiply;
import static util.MatrixOperationsF.normalize;
import graphics.raytracing.CastResult;
import graphics.raytracing.LightSource;
import graphics.raytracing.Shader;
import graphics.raytracing.Tracable;

public class FlatShader<T extends Tracable<? extends Tracable<T>>> implements Shader<T> {
	private LightSource _source;
	public FlatShader(LightSource source)
	{
		_source = source;
	}
	@Override
	public float[] shade(CastResult<T> result) {
		if(result==null)
			return ar(0,0,0,1);
		float colorization = multiply(normalize(result.getNormal()),normalize(_source.getDirection()));
		colorization=Math.min(1,Math.max(0,colorization) );
		float[] color = ar(1, 1, 1);
		color = multiply(color, colorization);
		return color;
	}

}
